package cn.lzx.user.controller;

import cn.lzx.basic.excpetion.BusinessExcpetion;
import cn.lzx.basic.util.AjaxResult;
import cn.lzx.user.domain.LoginDto;
import cn.lzx.user.service.ILogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {


    @Autowired
    private ILogininfoService logininfoService;

    @PostMapping("/account")
    public AjaxResult accountLogin(@RequestBody LoginDto loginDto){
        try {
            AjaxResult ajaxResult= logininfoService.accountLogin(loginDto);
            return ajaxResult;
        } catch (BusinessExcpetion e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("登录失败," + e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("系统异常," + e.getMessage());
        }
    }
}
